<layout name="layout"/>
<style type="text/css">
    #ul_pic_list li{margin:5px;}
    #old_pic_list li{float:left;width:150px;margin:5px;}
    #cat_list{background:#EEE;margin:0;width:250px;}
    #cat_list li{margin:5px;}
</style>
<div class="tab-div">
    <div id="tabbar-div">
        <p>
            <span class="tab-front">通用信息</span>
            <span class="tab-back" >商品描述</span>
            <span class="tab-back" >会员价格</span>
            <span class="tab-back" >商品属性</span>
            <span class="tab-back" >商品相册</span>
        </p>
    </div>

    <div id="tabbody-div">
        <form enctype="multipart/form-data" action=__SELF__ method="post">
            <input type="hidden" name="id" value="<?php echo $data['id']?>">
            <table width="90%"  align="center" class="tab_table">
                <tr>
                    <td class="label">商品名称：</td>
                    <td><input type="text" name="goods_name" value="{$data.goods_name}"size="30" />
                        <span class="require-field">*</span></td>
                </tr>
                <tr>
                    <td class="label">商品货号：</td>
                    <td>
                        <input type="text" name="goods_sn" value="" size="20"/>
                        <span id="goods_sn_notice"></span><br />
                        <span class="notice-span"id="noticeGoodsSN">如果您不输入商品货号，系统将自动生成一个唯一的货号。</span>
                    </td>
                </tr>
                <tr>
                    <td class="label">主分类：</td>
                    <td>
                        <select name="cat_id">
                            <option value="">选择分类</option>
                            <?php foreach ($catData as $k=>$v):
                                if($v['id'] == $data['cat_id'])
                                    $select = 'selected="selected"';
                                else
                                    $select = '';
                            ?>
                                <option <?php echo $select; ?> value="<?php echo $v['id']; ?>"><?php echo str_repeat('-',8*$v['level']).$v['cat_name']; ?></option>
                            <?php endforeach; ?>
                        </select>
                        <span class="require-field">*</span>
                    </td>
                </tr>
                <tr>
                    <td class="label">拓展分类：<input type="button" onclick="$('#cat_list').append($('#cat_list').find('li').eq(0).clone());" id="btn_add_cat" value="添加一个"></td>
                    <td>
                        <ul id="cat_list">
                            <?php if($gcData):  ?>
                            <?php foreach($gcData as $k1=>$v1): ?>
                            <li>
                                <select name="ext_cat_id[]">
                                    <option value="">选择分类</option>
                                    <?php foreach($catData as $k=>$v):
                                        if($v['id'] == $v1['cat_id']){
                                            $select = 'selected="selected"';
                                        } else {
                                            $select = '';
                                        }
                                    ?>
                                    <option <?php echo $select; ?> value="<?php echo $v['id']?>"><?php echo str_repeat('-',8*$v['level']).$v['cat_name']; ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </li>
                            <?php endforeach; ?>
                            <?php else: ?>
                            <li>
                                <select name="ext_cat_id[]">
                                    <option value="">选择分类</option>
                                    <?php foreach($catData as $k=>$v): ?>
                                    <option value="<?php echo $v['id']; ?>"><?php echo str_repeat('-',8*$v['level']).$v['cat_name']; ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </li>
                            <?php endif; ?>
                        </ul>
                    </td>
                </tr>
                <tr>
                    <td class="label">商品品牌：</td>
                    <td><?php buildSelect('brand','brand_id','id','brand_name',$data['brand_id']); ?></td>
                </tr>
                <tr>
                    <td class="label">商品数量：</td>
                    <td>
                        <input type="text" name="goods_number" size="8" value=""/>
                    </td>
                </tr>
                <tr>
                    <td class="label">商品LOGO：</td>
                    <td>
                        <?php echo showImage($data['sm_logo']); ?>
                        <input type="file" name="logo" size="35" />
                    </td>
                </tr>
                <tr>
                    <td class="label">排序：</td>
                    <td>
                        <input type="text" name="sort_num" size="8" value="<?php echo $data['sort_num']; ?>"/>
                    </td>
                </tr>
                <tr>
                    <td class="label">是否上架：</td>
                    <td>
                        <input type="radio" name="is_onsale" value="1" <if condition="$data.is_onsale eq 1"> checked="true" </if> /> 是
                        <input type="radio" name="is_onsale" value="0" <if condition="$data.is_onsale eq 0"> checked="true" </if> /> 否
                    </td>
                </tr>
                <tr>
                    <td class="label">是否推荐到楼层：</td>
                    <td>
                        <input type="radio" name="is_floor" value="1" <if condition="$data.is_floor eq '是'"> checked="true" </if> /> 是
                        <input type="radio" name="is_floor" value="0" <if condition="$data.is_floor eq '否'"> checked="true" </if> /> 否
                    </td>
                </tr>
                <tr>
                    <td class="label">促销价格：</td>
                    <td>
                        价格：￥<input type="text" name="promote_price" size="8" value="0.00"/>元
                        开始时间：<input type="text" id="promote_start_date" name="promote_start_date"/>
                        结束时间：<input type="text" id="promote_end_date" name="promote_end_date"/>
                    </td>
                </tr>
                <tr>
                    <td class="label">是否新品：</td>
                    <td>
                        <input type="radio" name="is_new" value="是" <if condition="$data.is_new eq '是'"> checked="true" </if> /> 是
                        <input type="radio" name="is_new" value="否" <if condition="$data.is_new eq '否'"> checked="true" </if>/> 否
                    </td>
                </tr>
                <tr>
                    <td class="label">是否精品：</td>
                    <td>
                        <input type="radio" name="is_best" value="是" <if condition="$data.is_best eq '是'"> checked="true" </if>/> 是
                        <input type="radio" name="is_best" value="否" <if condition="$data.is_best eq '否'"> checked="true" </if>/> 否
                    </td>
                </tr>
                <tr>
                    <td class="label">是否热卖：</td>
                    <td>
                        <input type="radio" name="is_hot" value="是" <if condition="$data.is_hot eq '是'"> checked="true" </if>/> 是
                        <input type="radio" name="is_hot" value="否" <if condition="$data.is_hot eq '否'"> checked="true" </if>/> 否
                    </td>
                </tr>
            </table>

            <table width="90%"  align="center" class="tab_table" style="display:none">
                <tr>
                    <td class="label"></td>
                    <td>
                        <textarea name="goods_desc" cols="40" rows="3" id="goods_desc">{$data.goods_desc}</textarea>
                    </td>
                </tr>
            </table>
            <table width="90%"  align="center" class="tab_table" style="display:none">
                <tr>
                    <td class="label">本店售价：</td>
                    <td>
                        <input type="text" name="shop_price" value="{$data.shop_price}" size="20"/>
                        <span class="require-field">*</span>
                    </td>
                </tr>
                <tr>
                    <td class="label">市场售价：</td>
                    <td>
                        <input type="text" name="market_price" value="{$data.market_price}" size="20" />
                    </td>
                </tr>
                <tr>
                    <td class="label">会员价格：</td>
                    <td>
                        <foreach name="mlData" item="val">
                            <strong>{$val.level_name}</strong>
                            ：￥<input type="text" name="member_price[{$val.id}]" size="8" value="<?php echo $mpData[$val['id']];?>"/>元<br/><br/>
                        </foreach>
                    </td>
                </tr>
            </table>

            <table width="90%"  align="center" class="tab_table" style="display:none">

                <tr>
                    <td>商品类型：<?php buildSelect('Type','type_id','id','type_name',$data['type_id']); ?></td>
                </tr>
                <tr>
                    <td >
                        <ul id="attr_list">
                       <?php
                        $attrId = array();
                        foreach($gaData as $k => $v):
                            if(in_array($v['attr_id'],$attrId))
                                $opt = '[-]';
                            else
                                $opt = '[+]';
                                $attrId[] = $v['attr_id'];
                        ?>
                        <li>
                            <input type="hidden" name="goods_attr_id[]" value="<?php echo $v['id']; ?>"/>
                            <?php if($v['attr_type'] == '可选'): ?>
                                <a onclick="addNewAttr(this);" href="#"><?php echo $opt; ?></a>
                            <?php endif; ?>
                            <?php echo $v['attr_name']; ?> :
                            <?php if($v['attr_option_values']):
                                $attr = explode(',',$v['attr_option_values']);
                            ?>
                            <select name="attr_value[<?php echo $v['attr_id']; ?>][]">
                                <option value="">请选择</option>
                                <?php foreach($attr as $k1 => $v1):
                                    if($v1 == $v['attr_value'])
                                        $select='selected="selected"';
                                    else
                                        $select='';
                                ?>
                                <option <?php echo $select; ?> value="<?php echo $v1; ?>"><?php echo $v1; ?></option>
                                <?php endforeach; ?>
                            </select>
                            <?php else: ?>
                                <input type="text" name="attr_value[<?php echo $v['attr_id']; ?>][]" value="<?php echo $v['attr_value']; ?>"/>
                            <?php endif; ?>
                        </li>
                        <?php endforeach; ?>
                    </ul></td>
                </tr>
            </table>
            <table width="90%"  align="center" class="tab_table" style="display:none">
                <tr>
                    <td>
                        <input type="button" id="btn_add_pic" value="添加一张"/>
                        <hr/>
                        <ul id="ul_pic_list"></ul>
                        <hr/>
                        <ul id="old_pic_list">
                            <?php foreach($gpData as $k=>$v): ?>
                            <li>
                                <input type="button" pic_id="<?php echo $v['id']; ?>" class="btn_del_pic" value="删除"><br/>
                                <?php showImage($v['mid_pic'],150); ?>
                            </li>
                            <?php endforeach; ?>
                        </ul>
                    </td>
                </tr>
            </table>
            </table>
            <div class="button-div">
                <input type="submit" value=" 确定 " class="button"/>
                <input type="reset" value=" 重置 " class="button" />
            </div>
        </form>
    </div>
</div>

<div id="footer">
    共执行 9 个查询，用时 0.025161 秒，Gzip 已禁用，内存占用 3.258 MB<br />
    版权所有 &copy; 2005-2012 上海商派网络科技有限公司，并保留所有权利。</div>

<script type="text/javascript">


</script>
</body>
<link href="__PUBLIC__/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="__PUBLIC__/umeditor/third-party/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__//umeditor/third-party/template.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/umeditor/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/umeditor/umeditor.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/umeditor/lang/zh-cn/zh-cn.js"></script>

<!--时间插件-->
<link href="__PUBLIC__/datetimepicker/jquery-ui-1.9.2.custom.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/datetimepicker/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/datetimepicker/datepicker-zh_cn.js"></script>
<link rel="stylesheet" media="all" type="text/css" href="__PUBLIC__/datetimepicker/time/jquery-ui-timepicker-addon.min.css" />
<script type="text/javascript" src="__PUBLIC__/datetimepicker/time/jquery-ui-timepicker-addon.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/datetimepicker/time/i18n/jquery-ui-timepicker-addon-i18n.min.js"></script>
<script>
    // 添加时间插件
    $.timepicker.setDefaults($.timepicker.regional['zh-CN']);  // 设置使用中文

    $("#promote_start_date").datetimepicker();
    $("#promote_end_date").datetimepicker();
</script>
<script type="text/javascript">
    UM.getEditor('goods_desc',{
        initialFrameWidth:'100%',
        initialFrameHeight:350
    });

    $("#tabbar-div p span").click(function () {
        var i = $(this).index();
        $(".tab_table").hide();
        $(".tab_table").eq(i).show();
        $(".tab-front").removeClass("tab-front").addClass("tab-back");
        $(this).removeClass("tab-back").addClass("tab-front");
    });

    $("#btn_add_pic").click(function () {
        var file = '<li><input type="file" name="pic[]"/></li>';
        $("#ul_pic_list").append(file);
    });

    $(".btn_del_pic").click(function () {
        if(confirm('是否删除?')){
            var li = $(this).parent();
            var pid = $(this).attr("pic_id");
            $.ajax({
                type : "GET",
                url  : "<?php echo U('ajaxDelPic','',FALSE); ?>/picid/"+pid,
                success : function (data) {
                    li.remove();
                }
            });
        }
    });

    $("select[name=type_id]").change(function () {
        var typeId = $(this).val();
        if(typeId > 0){
            $.ajax({
                type : "GET",
                url  : "<?php echo U('ajaxGetAttr','',FALSE); ?>/type_id/"+typeId,
                dataType : "json",
                success : function (data) {
                    var li = "";
                    $(data).each(function (k,v) {
                        li += '<li>';
                        //如果属性为可选值，则前面有个+
                        if(v.attr_type == '可选')
                            li += '<a onclick="addNewAttr(this);" href="#">[+]</a>';
                        //属性名称
                        li += v.attr_name + ' : ';
                        //如果属性是可选值则做下拉框，否则文本框
                        if(v.attr_option_values == ""){
                            li += '<input type="text" name="attr_value['+v.id+'][]" />';
                        } else {
                            li += '<select name="attr_value['+v.id+'][]"><option value="">请选择</option>';
                            var _attr = v.attr_option_values.split(',');
                            for(var i=0;i<_attr.length;i++){
                                li += '<option value="'+_attr[i]+'">';
                                li += _attr[i];
                                li += '</option>';
                            }
                            li += '</select>';
                        }
                        li += '</li>';
                    });
                    $("#attr_list").html(li);
                }
            });
        }
        else
            $("#attr_list").html("");
    });

    function addNewAttr(a) {
        var li = $(a).parent();
        if($(a).text() == '[+]'){
            var newLi = li.clone();
            newLi.find("option:selected").removeAttr("selected");
            newLi.find("input[name='goods_attr_id[]']").val("");
            newLi.find("a").text('[-]');
            li.after(newLi);
        } else {
            var gaid = li.find("input[name='goods_attr_id[]']").val();
            if(gaid == ''){
                li.remove();
            } else {
                if(confirm('如果删除这个属性，那么相关的库存量数据也会一起删除，确定要删除吗？')){
                    $.ajax({
                        type : "GET",
                        url : "<?php echo U('ajaxDelAttr?goods_id='.$data['id'],'',FALSE); ?>/gaid/"+gaid,
                        success : function (data) {
                            li.remove();
                        }
                    });
                }
            }
        }
    }
</script>
</html>